package org.hqs.doctor.service;

import org.hqs.doctor.mapper.DoctorMapper;
import org.hqs.doctor.pojo.Doctor;
import org.hqs.feign.clients.DepartmentClient;
import org.hqs.feign.pojo.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static java.lang.Long.valueOf;


@Service
public class DoctorService {
    @Autowired
    private DoctorMapper doctorMapper;

    @Autowired
    private DepartmentClient departmentClient;

    public Doctor queryDoctorById(Long doctorId) {
        Doctor doctor = doctorMapper.findById(doctorId);
        System.out.println(doctor);
        Department department = departmentClient.getDepartmentById(valueOf(doctor.getDepartmentId())).getData();
        doctor.setDepartment(department);
        return doctor;
    }

    public List<Doctor> findAllDoctors() {
        return doctorMapper.findAllDoctors();
    }

    public int addDoctor(Doctor doctor) {
        return doctorMapper.insertDoctor(doctor);
    }

    public int updateDoctor(Doctor doctor) {
        return doctorMapper.updateDoctor(doctor);
    }

    public int deleteDoctor(Long id) {
        return doctorMapper.deleteDoctor(id);
    }
}
